package com.hairline.controller;

import com.hairline.bean.vo.BaseRespVo;
import com.hairline.bean.vo.WxSearchIndexVo;
import com.hairline.service.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fenglin on 2020/9/4 3:52 PM
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {

    @Autowired
    WxSearchService wxSearchService;

    @GetMapping("index")
    public BaseRespVo searchIndex(){
        WxSearchIndexVo keyword = wxSearchService.searchIndex();
        return BaseRespVo.ok(keyword);
    }

    @GetMapping("helper")
    //TODO
    public BaseRespVo searchHelper(String keyword){
        //返回模糊匹配到的数组  ["测试111","123"]
        List<String> keywordList = wxSearchService.searchHelper(keyword);
        //List<String> keywordList = new ArrayList<>();
        return BaseRespVo.ok(keywordList);
    }

    @PostMapping("clearhistory")
    public BaseRespVo searchClearHistory(){
        wxSearchService.clearhistory();
        return BaseRespVo.ok();
    }
}
